<?php

namespace app\admin\controller;

/**
* 
*/
class Admin extends Base
{
 	//会员列表
 	public function list_l(){
 		$admin=model('Admin')->order('id','desc')->paginate(10);
 		$viewData=[
 			'admin'=>$admin
 		];
 		$this->assign($viewData);
 		return view();
 	}



 	//会员添加
 	public function add(){
 		if(request()->isAjax()){
 			$data=[
 				'username'=>input('post.username'),
 				'password'=>input('post.password'),
 				'conpass'=>input('post.conpass'),
 				'nickname'=>input('post.nickname'),
 				'email'=>input('post.email'),
 			];
 			$result=model('Member')->add($data);
 			if($result==1){
 				$this->success('添加成功','admin/member/list_l');
 			}else{
 				$this->error($result);
 			}
 		}

 		return view();
 	}

 	//会员编辑
 	public function edit(){
 		if(request()->isAjax()){
 			$data=[
 				'id'=>input('post.id'),
 				'status'=>input('post.status'),
 				'is_super'=>input('post.is_super'),				
 				'nickname'=>input('post.nickname'),
 				'email'=>input('post.email'),
 			];
 			$result=model('Admin')->edit($data);
 			if($result==1){
 				$this->success('修改成功！','admin/admin/list_l');
 			}else{
 				$this->error($result);
 			}
 		}
 		$adminInfo=model('Admin')->find(input(input('get.id')));
 		$viewData=[
 			'adminInfo'=>$adminInfo
 		];
 		$this->assign($viewData);
 		return view();
 	}
 	// //会员删除
 	// public function del(){
 	// 	if(request()->isAjax()){
 	// 		$data=['id'=>input('post.id')];
 	// 	$memberInfo=model('Member')->find($data['id']);
 	// 	$result=$memberInfo->delete();
 	// 	if($result==1){
 	// 		$this->success('删除成功！','admin/member/list_l');
 	// 	}else{
 	// 		$this->error($result);
 	// 	}
 	// 	}

 	// }
 	//管理员删除
 	public function del(){
 		if(request()->isAjax()){
 			$adminInfo=model('Admin')->find(input('post.id'));
 			$result=$adminInfo->delete();
 			if($result){
 				$this->success('删除成功！','admin/admin/list_l');
 			}else{
 				$this->error($result);
 			}

 		}
 	}
}






